Space Invaders

Earth is being invaded by martians. Here's a description of the Martian fleet:

  1. The Martians have some spaceships.
  2. Each spaceship is either a mother ship or a drone.
  3. A mother ship has a name, which is a String, a crew, which is a list of Martians, and a possibly-empty set of daughter ships, each of which is a spaceship.
  4. When we say the fleet of a spaceship, we mean her daughter ships and all their fleets.
  5. A Martian has a name, which is a string, and some other attributes, which are unspecified.

Write functions to accomplish the following tasks. For each function, draw its call graph, and write a halting measure. Be prepared to explain why your halting measure decreases around every cycle in the graph.

  1. Given a spaceship, is there a Martian named "Mork" in its crew?
  2. Given a spaceship, is there a Martian named "Mork" in its own crew or in the crew of one of its daughter ships?
  3. Given a spaceship, how many Martians named "Mork" are in the crew of either the spaceship or its fleet?
  4. Given a spaceship, return another spaceship just like the original, except that all of its daughters that are drones have been removed.
  5. Given a spaceship, return another spaceship just like the original, except that all of the drones in its fleet have been removed.
  6. Given a spaceship, return another spaceship just like the original, except that all of its daughters who have a crewmember named "Mork" have been removed. When a daughter is removed from the fleet, so are all its daughters and their fleets.
  7. Given a spaceship, return another spaceship just like the original, except that every ship in its fleet who has a crewmember named "Mork" has been removed. When a ship is removed from the fleet, so are all its daughters and their fleets.

Last modified: Tue Oct 18 12:16:23 Eastern Daylight Time 2016